﻿using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Markup;

namespace XamlInspector.Presentation.Controls
{
    [ContentProperty(Name = "Content")]
    public class LazyExpander : Control
    {
        public LazyExpander()
        {
            DefaultStyleKey = typeof (LazyExpander);
        }

        public object Header
        {
            get { return (object)GetValue(HeaderProperty); }
            set { SetValue(HeaderProperty, value); }
        }

        // Using a DependencyProperty as the backing store for Header.  This enables animation, styling, binding, etc...
        public static readonly DependencyProperty HeaderProperty =
            DependencyProperty.Register("Header", typeof(object), typeof(LazyExpander), new PropertyMetadata(null));


        public bool IsExpanded
        {
            get { return (bool)GetValue(IsExpandedProperty); }
            set { SetValue(IsExpandedProperty, value); }
        }

        // Using a DependencyProperty as the backing store for IsExpanded.  This enables animation, styling, binding, etc...
        public static readonly DependencyProperty IsExpandedProperty =
            DependencyProperty.Register("IsExpanded", typeof(bool), typeof(LazyExpander), new PropertyMetadata(null, OnExpanded));

        private static void OnExpanded(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var control = (LazyExpander) sender;
            if ((bool) e.NewValue)
            {
                control.ExpandedContent = control.Content;
            }
        }

        public object Content
        {
            get { return (object)GetValue(ContentProperty); }
            set { SetValue(ContentProperty, value); }
        }

        // Using a DependencyProperty as the backing store for Content.  This enables animation, styling, binding, etc...
        public static readonly DependencyProperty ContentProperty =
            DependencyProperty.Register("Content", typeof(object), typeof(LazyExpander), new PropertyMetadata(null));


        public object ExpandedContent
        {
            get { return (object)GetValue(ExpandedContentProperty); }
            set { SetValue(ExpandedContentProperty, value); }
        }

        // Using a DependencyProperty as the backing store for ExpandedContent.  This enables animation, styling, binding, etc...
        public static readonly DependencyProperty ExpandedContentProperty =
            DependencyProperty.Register("ExpandedContent", typeof(object), typeof(LazyExpander), new PropertyMetadata(null));

        
        
    }
}
